package com.cwx.controller;

import com.cwx.domain.User;
import com.cwx.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/findAll")
    //查询所有用户信息
    public ModelAndView findAll(){
        ModelAndView mv = new ModelAndView();
        List<User> userList = userService.findAll();
        mv.addObject("userList",userList);
        mv.setViewName("user-list");
        return mv;
    }

    @RequestMapping("/delete")
    //删除用户信息
    public String delete(Integer id){

        userService.deleteOneUser(id);
        System.out.println("2222222222222222");
        System.out.println("22222222222222221111111");
        System.out.println("6666666666666666666666666666");

        //我改变了一下
        return "user-list";
    }

    //根据id进行查询
    @RequestMapping("/findById/{id}")
    //查询所有用户信息
    public ModelAndView findById(@PathVariable("id") Integer id){
        ModelAndView mv = new ModelAndView();
        User user = userService.findById(id);
        mv.addObject("user",user);
        mv.setViewName("user-list");

//        mv.addObject("userList",userList);
//        mv.setViewName("user-list");
        //en  我知道,明天给你搞哈
        System.out.println("222222");
        return mv;
    }

}


